<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use App\Admin;

class LoginController extends Controller
{
    public function index(){
        return view('login/index');
    }

    public function login(Request $request){
        $res = $request->all();
        //var_dump($res);exit;
        if(!$res['username'] || !$res['password']){
            return response()->json(['code'=>1,'msg'=>'参数缺失']);
        }
        $data = Auth::guard('admin')->attempt([
            'username' => $res['username'],
            'password' => $res['password']
        ]);
        if($data){
            return redirect('admin/admin');
        }else{
            return redirect('admin/index');
        }

    }

    public function loginout(){
        Auth::guard('admin')->logout();
        return response()->json(['code'=>0,'msg'=>'成功退出登录']);
    }

}